package cn.genmer.test.security.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * @author Jack.Lee
 * @description
 * @create 2019-04-20 14:27
 * @program cuckoo-gis
 **/
public class ValidateUtils {
	/**国家保密地址*/
	private static String[] keyWords = {"监狱", "看守所", "武警", "部队"} ;
	/**完整省名*/
	public static String[] complete_provinces = {"北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省", "黑龙江省", "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省",
			"山东省", "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省", "云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区"};
	/**简写省名*/
	public static String[] provinces = {"安徽","北京","福建","甘肃","广东","广西","贵州","海南","河北","河南","黑龙江","湖北","湖南","吉林","江苏","江西",
			"辽宁","内蒙古","宁夏","青海","山东","山西","陕西","上海","四川","台湾","天津","西藏","香港","新疆","云南","浙江","重庆","澳门"};



	/**
	 * 判断地址是否包含省名
	 * @param address
	 * @return
	 */
	public static boolean isContainsProvinceName(String address){
		for(int i=0;i<provinces.length;i++){
			if(address.contains(provinces[i] )){
				return true;
			}
		}
		return false;
	}


	/**
	 * 大陆号码或香港号码均可
	 */
	public static boolean isPhoneLegal(String str)throws PatternSyntaxException {
		return isChinaPhoneLegal(str) || isHKPhoneLegal(str);
	}

	/**
	 * 大陆手机号码验证
	 */
	public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {
//		String regExp = "^((13[0-9])|(15[^4])|(16[0-9])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";
		String regExp = "^1[3456789][0-9]{9}";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.matches();
	}

	/**
	 * 香港手机号码8位数，5|6|8|9开头+7位任意数
	 */
	public static boolean isHKPhoneLegal(String str)throws PatternSyntaxException {
		String regExp = "^(5|6|8|9)\\d{7}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.matches();
	}

    public static boolean isContainsKeyWords(String address) {
		for(int i=0;i<keyWords.length;i++){
			if(address.contains(keyWords[i] )){
				return true;
			}
		}
		return false;
    }

	public static boolean isEmptyStr(String str){
		if(StringUtils.isBlank(str) || "null".equals(str)){
			return true;
		}
		return false ;
	}

	/**
	 * 是否是规范地址
	 * @Author Xw.H
	 * @param address 地址
	 * @return true:规范地址 false:不规范地址
	 **/
	public static boolean isNormAddress(String address){
		String regex = "^[0-9A-Za-z\\-]+$";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(address);
		return !m.matches();
	}

}
